package com.zhang.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhang.entity.DeviceInfo;
import com.zhang.entity.ExecutionResults;
import com.zhang.mapper.DeviceInfoMapper;
import com.zhang.mapper.ExecutionResultsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.zhang.common.Constant.DEVICE_NOT_ALIVE;


/**
 * User: 张
 * Date: 2024-11-14
 * Time: 21:40
 * Description:
 */
@Service
public class DeviceInfoService {
    @Autowired
    private DeviceInfoMapper deviceInfoMapper;
    @Autowired
    private ExecutionResultsMapper executionResultsMapper;

    public PageInfo<DeviceInfo> getDeviceInfo(Integer pageNum, Integer pageSize, DeviceInfo deviceInfo){
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(deviceInfoMapper.getDeviceInfo(deviceInfo));
    }

    public Boolean addDeviceInfo(DeviceInfo deviceInfo){
        return deviceInfoMapper.addDeviceInfo(deviceInfo) > 0;
    }

    public Boolean updateDeviceInfo(DeviceInfo deviceInfo){
        return deviceInfoMapper.updateDeviceInfo(deviceInfo) > 0;
    }

    public Boolean deleteDeviceInfo(Integer deviceId){
        return deviceInfoMapper.updateDeviceState(deviceId,DEVICE_NOT_ALIVE) > 0;
    }

    public PageInfo<ExecutionResults> getDeviceLog(ExecutionResults executionResults,Integer pageSize,Integer pageNum){
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(executionResultsMapper.getDeviceLog(executionResults));
    }

}
